package com.action.app_landing;

import java.io.File;

import java.io.PrintWriter;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;





import org.apache.struts2.ServletActionContext;
import org.json.JSONObject;



import com.enetiy.Area;
import com.enetiy.Areaip;
import com.enetiy.Binding;
import com.enetiy.Logins;
import com.enetiy.Recommend;
import com.enetiy.Ticket;
import com.enetiy.Ticketuser;
import com.enetiy.Useraccount;
import com.enetiy.Userinfo;
import com.enetiy.Users;
import com.operation.ChatRongyun;
import com.operation.GateIP;
import com.operation.NET;
import com.service.AreaIpService;
import com.service.AreaService;
import com.service.AuthCodeService;
import com.service.BindingService;
import com.service.DealService;
import com.service.LoginService;
import com.service.RecommendService;
import com.service.TicketService;
import com.service.UseraccountService;
import com.service.UserinfoService;
import com.threads.NetoutThread;
import com.threads.PublicIPThread;
import com.util.DataUtil;
import com.util.IPUtil;
import com.util.Log4gUtil;
import com.util.Md5Util;
import com.util.RandomUtil;

public class LoginAction {
	private String account;//手机号
	private String pwd;//密码
	private int accountType;//账户类型
	private String soleCode;//手机唯一码
	private String authcode;//手机验证码
	private int siteAreaid;//所在区域（关口）
	private String openId;//微信
	
	private String nickname;//昵称
	private int sex;
	private String ip;//IP地址
	private String token; //Token码
	private String mac;//mac地址
	private String ver;//app版本号
	private String hotspotName;//热点名称
	private int userid;//用户id
	private String deviceType;//客户端类型
	private String deviceVer;//客户端版本
	private String NF_callid;
	
	private String recommend;
	private String params;
	
	private UserinfoService userinfoService;
	private LoginService loginService;
	private AuthCodeService authCodeService;
	private BindingService bindingService;
	private AreaService areaService;
	private UseraccountService useraccountService;
	private AreaIpService areaIpService;
	private DealService dealService;
	private TicketService ticketService;
	private RecommendService recommendService;
	
	/**
	 * 重设密码 
	 */
	public void resetPwd(){
		if(params!=null&&!params.equals("")){
			JSONObject datajson = DataUtil.dataParser(params);
			if(datajson.has("pwd"))
				pwd=datajson.getString("pwd");
			if(datajson.has("userid"))
				userid =datajson.getInt("userid");
		}
		
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out=null;
		net.sf.json.JSONObject j = DataUtil.sendJson();	
		try {
			out = response.getWriter();
			Users user = loginService.selectUserId(userid);
			if(user!=null){
				user.setPwd(pwd);
				loginService.updateUser(user);
				j.put("code", 1);
			}else{
				j.put("code",-1);
				j.put("msg","用户不存在");
			}
		} catch (Exception e) {
			j.put("code",-1);
			j.put("msg","服务器异常");
			e.printStackTrace();
		}
		System.out.println("修改密码-输出--:"+j.toString());
		out.print(j);
	}
	
	
	/**
	 * 账号app登录及注册  >Nf004
	 * 
	 */
	public void accountEnroll(){
		long startTime = new Date().getTime();
		if(params!=null&&!params.equals("")){
			JSONObject dataParser = DataUtil.dataParser(params);
			if(dataParser.has("account"))
				account = dataParser.getString("account");
			if(dataParser.has("pwd"))
				pwd = dataParser.getString("pwd");
			if(dataParser.has("soleCode"))
				soleCode = dataParser.getString("soleCode");
			if(dataParser.has("accountType"))
				accountType = dataParser.getInt("accountType");
			if(dataParser.has("authcode"))
				authcode = dataParser.getString("authcode");
			
			if(dataParser.has("mac"))
				mac = dataParser.getString("mac");
			if(dataParser.has("deviceType"))
				deviceType = dataParser.getString("deviceType");
			if(dataParser.has("deviceVer"))
				deviceVer = dataParser.getString("deviceVer");
			if(dataParser.has("ip"))
				ip = dataParser.getString("ip");
			if(dataParser.has("ver"))
				ver = dataParser.getString("ver");
			if(dataParser.has("siteAreaid"))
				siteAreaid = dataParser.getInt("siteAreaid");
		}
		Log4gUtil.Info("accountEnroll", userid+"", "进入账号登陆param:", params, NF_callid, token);
		
		HttpServletResponse response = ServletActionContext.getResponse();
		net.sf.json.JSONObject send =DataUtil.sendJson();
		PrintWriter out = null;
		try {
			out = response.getWriter();
			Users user = null;
			Userinfo userinfo = null;
			boolean norm = false;
			
			//查询账号
			Useraccount useraccount =useraccountService.selectUseraccount(account);
			if(useraccount != null){  
				/*
				 *账号存在
				 *1.验证   如手机验证码不为空 验证手机验证码,否则验证密码  是否正确
				 *2.查询  如验证通过,根据用户账号查询此用户信息,如有用户网络在线使其下线,标记用户可以登录
				 */
				//验证 手机验证码 或 密码正确
				boolean fig=false;
				//手机验证码不为空,并 正确
				if(authcode!=null&&!authcode.equals("")&&authCodeService.selectAuthCode(account, authcode))
					fig = true;
				else //否则账号密码不为空,并 正确
				if(pwd != null && !pwd.equals("")&&useraccount.getUsers().getPwd().equals(pwd))
					fig = true;
				
				if(fig){//登录验证通过
					//查询用户信息
					
					userinfo = userinfoService.selectUserinfo(useraccount.getUsers().getId());
					
					
					
					user=useraccount.getUsers();
					
					Userinfo userinfo2 = userinfo;
					//如有用户网络在线
					if(userinfo2.getArea()!=null){
						//原用户网络下线  分支线程
 						NetoutThread lt = new NetoutThread();
						lt.account=account;
						lt.userid=userinfo2.getUsers().getId();
						lt.dealService=dealService;
						lt.areaIpService = areaIpService;
						lt.userinfo = userinfo2;
						lt.callid = NF_callid;
						lt.token = userinfo2.getToken();
						Thread t1 = new Thread(lt); 
						t1.start();
					}
					Log4gUtil.Info("accountEnroll", user.getId()+"", "已有账号通过验证-账号", account, NF_callid, token);
					
					norm = true;
				}else{
					send.put("code", 0);
					send.put("msg", "已有账号验证未通过");
					Log4gUtil.Info("accountEnroll", userid+"", "已有账号未通过验证-账号", account, NF_callid, token);
				}
			}else{
				/*
				 *如账号不存在
				 *1.查询   根据手机唯一码是否存在 ;  并验证   验证手机验证码是否正确
				 *2.如通过1步,则添加账号,修改用户信息,标记用户可以登录
				 */
				if(authCodeService.selectAuthCode(account, authcode)){
					//查询唯一码是否存在
					if((user = loginService.selectUser(soleCode))!=null){
						//修改用户
						user.setSoleCode(soleCode+user.getId());
						//用户账号信息
						useraccount = new Useraccount();
						useraccount.setAccount(account);//账号
						useraccount.setStatus(1);//账号状态(1:可以使用,0:不可以使用)
						useraccount.setAccountype(accountType);//账号类型(1:手机)
						useraccount.setUsers(user);//所属用户
						//添加账号
						useraccountService.insetrUseraccount(useraccount);
						//查询用户信息
						userinfo = userinfoService.selectUserinfo(user.getId());
						Log4gUtil.Info("accountEnroll", user.getId()+"", "新账号通过验证-账号", account, NF_callid, token);
					}else{
						//不存在soleCode 添加用户
						
						//默认头像路劲
						String realPath = IPUtil.getFilePath()+"/img/uersImg/headImg/MoRenHead/";
						File f = new File(realPath);
						//路劲底所有图片
						String[] list = f.list();
						String headimg ="";
						if(list!=null)
							headimg ="MoRenHead/"+list[0];
						
						user = new Users();
						if(pwd==null){
							pwd="";
						}
						user.setPwd(pwd);
						user.setFirstlogin(new Date());
						user.setNickname(nickname);
						user.setHeadImg(headimg);
						user.setSex(sex);
						
						//添加用户(游客)
						Serializable usersid = loginService.insertUsers(user);
						user.setId(Integer.parseInt(usersid.toString()));
						
						//生成App token码
						String usertoken = this.getToken(account,Math.random()*100+"");
						//缓存token
						opApplic(usersid+"", usertoken);
						
						userinfo = new Userinfo();
						userinfo.setToken(usertoken);//更新token
						userinfo.setUsers(user);
						//添加用户信息
						userinfoService.insertUserinfo(userinfo);
						//用户账号信息
						useraccount = new Useraccount();
						useraccount.setAccount(account);//账号
						useraccount.setStatus(1);//账号状态(1:可以使用,0:不可以使用)
						useraccount.setAccountype(accountType);//账号类型(1:手机)
						useraccount.setUsers(user);//所属用户
						//添加账号
						useraccountService.insetrUseraccount(useraccount);
						
						//登陆成功,记录登陆
						Logins l = this.setLoginInfo(ip, user, mac, hotspotName, ver, deviceType, deviceVer, siteAreaid);
						loginService.insertLogins(l);
					}
					norm = true;
				}else{
					send.put("code", 0);
					send.put("msg", "新账号验证未通过");
					Log4gUtil.Info("accountEnroll", userid+"", "新账号未通过验证-账号", account, NF_callid, token);
				}
			}
			
			if(norm){//用户账号登陆后操作
				/*
				 * 用户账号登陆后操作
				 * 1.更新token码 等 用户信息字段
				 * 2.准备发送客户端数据
				 */
				
				//生成App token码
				String usertoken = this.getToken(useraccount.getAccount(),"");
				//缓存token
				opApplic(useraccount.getUsers().getId()+"", usertoken);
				userinfo.setToken(usertoken);//更新token
				userinfo.setAppOnline(1);//app 在线状态(1:在线,0:不在线)
				
				//融云注册码为空
				if(userinfo.getChatToken()==null||userinfo.getChatToken().equals("")){
					//融云注册
					String chatToken = ChatRongyun.getChatToken(user.getId(), user.getNickname(), user.getHeadImg());
					userinfo.setChatToken(chatToken);
				}
				
				//如牛号为空,添加牛号
				if(user.getNiuNum()==null||user.getNiuNum().equals("")){
					user.setNiuNum(getNiunum(user.getId()));
				}
				
				userinfoService.updateUserinfo(userinfo);
				loginService.updateUser(user);
				
				send.put("code", 1);
				send.put("status", 1);//登陆状态,1为已登录
				send.put("token", userinfo.getToken()); //token码
				send.put("siteAreaid", siteAreaid);//所在区域
				send.put("userid", user.getId());
				send.put("sex", user.getSex());//性别
				//密码 1:已有密码;0:无密码
				if(user.getPwd()!=null&&!user.getPwd().equals(""))
					send.put("pwd", 1);
				else
					send.put("pwd", 0);
				send.put("selfdom",user.getSelfdom());//个性签名
				send.put("niuNum", user.getNiuNum());//牛号
				send.put("chatToken",userinfo.getChatToken());//融云token
				send.put("nickname", user.getNickname());//昵称
				send.put("headimg", IPUtil.getIp()+"/img/uersImg/headImg/"+user.getHeadImg());//头像
				//登陆成功,记录登陆
				Logins l = this.setLoginInfo(ip, user, mac, hotspotName, ver, deviceType, deviceVer, siteAreaid);
				loginService.insertLogins(l);
			}
		} catch (Exception e) {
			send.put("code", -1);
			e.printStackTrace();
		}
		out.print(send);
		Long endTime = new Date().getTime();
		Log4gUtil.Info("accountEnroll", userid+"", "输出账号登录时间", (startTime-endTime)+"-"+send.toString(), NF_callid, token);
	}
	/**
	 * 
	 * 网页登录及注册  >Nf005
	 */
	public void accountEnrollPC(){
		long startTime = new Date().getTime();
		if(params!=null&&!params.equals("")){
			JSONObject dataParser = DataUtil.dataParser(params);
			if(dataParser.has("account"))
				account = dataParser.getString("account");
			if(dataParser.has("pwd"))
				pwd = dataParser.getString("pwd");
			if(dataParser.has("accountType"))
				accountType = dataParser.getInt("accountType");
			if(dataParser.has("authcode"))
				authcode = dataParser.getString("authcode");
			if(dataParser.has("recommend"))
				recommend = dataParser.getString("recommend");
			if(dataParser.has("siteAreaid"))
				siteAreaid = dataParser.getInt("siteAreaid");
		}
		Log4gUtil.Info("accountEnrollPC", userid+"", "进入账号PC登录param", params, NF_callid, token);
		HttpServletResponse response = ServletActionContext.getResponse();
		net.sf.json.JSONObject send =DataUtil.sendJson();
		PrintWriter out = null;
		try {
			out = response.getWriter();
			Users user = null;
			Userinfo userinfo = null;
			
			//查询账号
			Useraccount useraccount =useraccountService.selectUseraccount(account);
			if(useraccount != null){  
				/*
				 *账号存在
				 *1.验证   如手机验证码不为空 验证手机验证码,否则验证密码  是否正确
				 *2.查询  如验证通过,根据用户账号查询此用户信息,如有用户网络在线使其下线,标记用户可以登录
				 */
				//验证 手机验证码 或 密码正确
				boolean fig=false;
				//手机验证码不为空,并 正确
				if(authcode!=null&&!authcode.equals("")&&authCodeService.selectAuthCode(account, authcode)){
					fig = true;
				}else //否则账号密码不为空,并 正确
				if(pwd != null && !pwd.equals("")&&useraccount.getUsers().getPwd().equals(pwd)){
					fig = true;
				}
				
				//登录验证通过
				if(fig){
					userinfo = userinfoService.selectUserinfo(useraccount.getUsers().getId());
					
					if(siteAreaid!=10005){//10005卓能不下
						//如有用户网络在线
						if(userinfo.getArea()!=null){
							//原用户网络下线  分支线程
	 						NetoutThread lt = new NetoutThread();
							lt.account=account;
							lt.dealService=dealService;
							lt.areaIpService = areaIpService;
							lt.userid=userid;
							lt.callid = NF_callid;
							lt.userinfo = userinfo;
							lt.token = userinfo.getToken();
							Thread t1 = new Thread(lt); 
							t1.start();
						}
					}
					
					//查询用户信息
					userinfo.setAppOnline(1);
					//缓存token
					opApplic(useraccount.getUsers().getId()+"", userinfo.getToken());
					
					int bindIden = 0;
					Binding binding = bindingService.selectbinding(userid, siteAreaid);
					if(binding!=null)
						bindIden = 1;
					
					user=useraccount.getUsers();
					send.put("code", 1);
					send.put("userid", user.getId());
					send.put("bindIden", bindIden);//绑定标示, 0为没有绑/1为有绑
					send.put("iden", 0);//标示是否为注册  0为登录 1为注册
					send.put("token", userinfo.getToken());
					Log4gUtil.Info("accountEnrollPC", user.getId()+"", "已有账号通过验证-账号", account, NF_callid, token);
					
					//登陆成功,记录登陆
					Logins l = this.setLoginInfo(ip, user, mac, hotspotName, ver, "PC", deviceVer, siteAreaid);
					loginService.insertLogins(l);
				}else{
					send.put("code", 0);
					send.put("msg", "账号验证未通过");
					Log4gUtil.Info("accountEnrollPC", userid+"", "已有账号未通过验证-账号", account, NF_callid, token);
				}
			}else{//没有账号  注册
				if(authCodeService.selectAuthCode(account, authcode)){
					
					//默认头像路劲
					String realPath = IPUtil.getFilePath()+"/img/uersImg/headImg/MoRenHead/";
					File f = new File(realPath);
					//路劲底所有图片
					String[] list = f.list();
					String headimg ="";
					if(list!=null)
						headimg ="MoRenHead/"+list[0];
					user = new Users();
					if(pwd==null){
						pwd="";
					}
					user.setPwd(pwd);
					user.setFirstlogin(new Date());
					user.setNickname(nickname);
					user.setHeadImg(headimg);
					user.setSex(sex);
					
					//添加用户
					Serializable usersid = loginService.insertUsers(user);
					
					user.setId(Integer.parseInt(usersid.toString()));
					
					//生成App token码
					String usertoken = this.getToken(account,Math.random()*100+"");
					//缓存token
					opApplic(usersid+"", usertoken);
					userinfo = new Userinfo();
					userinfo.setToken(usertoken);//更新token
					userinfo.setUsers(user);
					userinfo.setAppOnline(1);
					
					//添加用户信息
					userinfoService.insertUserinfo(userinfo);
					
					//用户账号信息
					useraccount = new Useraccount();
					useraccount.setAccount(account);//账号
					useraccount.setStatus(1);//账号状态(1:可以使用,0:不可以使用)
					useraccount.setAccountype(accountType);//账号类型(1:手机)
					useraccount.setUsers(user);//所属用户
					
					//添加账号
					useraccountService.insetrUseraccount(useraccount);
					
					//推荐券
					if(recommend!=null&&recommend.equals("")){
						Recommend commend = recommendService.selectRecommend(recommend);
						if(commend != null){
							Users u = loginService.selectUserId(commend.getUserid());
							Ticket ticket = ticketService.selectTicket("ticket-02");
							ticketService.insertTickeUser(new Ticketuser(u,ticket,new Date(),null,0,ticket.getGiveTime()));
						}
					}
					
					send.put("code", 1);
					send.put("userid", user.getId());
					send.put("bindIden", 0);//绑定标示, 0为没有绑/1为有绑
					send.put("iden", 1);//标示是否为注册  0为登录 1为注册
					send.put("token", userinfo.getToken());
					
					//登陆成功,记录登陆
					Logins l = this.setLoginInfo(ip, user, mac, hotspotName, ver, "PC", deviceVer, siteAreaid);
					loginService.insertLogins(l);
					
				}else{
					send.put("code", 0);
					send.put("msg", "账号验证未通过");
					Log4gUtil.Info("accountEnrollPC", userid+"", "新账号未通过验证-账号", account, NF_callid, token);
				}
			}
		} catch (Exception e) {
			send.put("code", -1);
			e.printStackTrace();
		}
		long endTime = new Date().getTime();
		Log4gUtil.Info("accountEnrollPC", userid+"", "输出账号登录时间", (startTime-endTime)+"-"+send.toString(), NF_callid, token);
		out.print(send);
	}
	
	/********
	 * 
	 * Token登录及游客登录  >Nf003
	 */
	public void visitorLogin(){
		long startTime = new Date().getTime();
		if(params!=null&&!params.equals("")){
			JSONObject dataParser = DataUtil.dataParser(params);
			if(dataParser.has("soleCode"))
				soleCode = dataParser.getString("soleCode");
			if(dataParser.has("token"))
				token = dataParser.getString("token");
			if(dataParser.has("userid"))
				userid = dataParser.getInt("userid");
			
			if(dataParser.has("mac"))
				mac = dataParser.getString("mac");
			if(dataParser.has("deviceType"))
				deviceType = dataParser.getString("deviceType");
			if(dataParser.has("deviceVer"))
				deviceVer = dataParser.getString("deviceVer");
			if(dataParser.has("ip"))
				ip = dataParser.getString("ip");
			if(dataParser.has("ver"))
				ver = dataParser.getString("ver");
		}
		Log4gUtil.Info("visitorLogin", userid+"", "进入自动登录param", params, NF_callid, token);
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		net.sf.json.JSONObject j =DataUtil.sendJson();
		try {
			//如请求为代理服务请求, 存储其公网地址
			if(siteAreaid!=0&&siteAreaid!=90){
				HttpServletRequest request = ServletActionContext.getRequest();
				String ip = GateIP.getIP(request);
				PublicIPThread publicip =  new PublicIPThread(areaIpService, siteAreaid,ip);
				Thread t = new Thread(publicip);
				t.start();//开启线程
			}
			
			Userinfo userinfo=null; 
			Users user =  null;
			int status = 0;
			String newtoken = "null";
			out = response.getWriter();
			
			Area area = areaService.selectArea(siteAreaid);
			//验证token是否存在
			if((userinfo=userinfoService.selectUserToken(token, userid))==null){
				/**
				 * 一.如token不存在,查询soleCode码是否存在
				 */
				if((user = loginService.selectUser(soleCode))==null){
					/**
					 * 1.如soleCode不存在,添加用户为游客和用户初始信息保存soleCode
					 */
					//默认头像路劲
					String realPath = IPUtil.getFilePath()+"/img/uersImg/headImg/MoRenHead/";
					File f = new File(realPath);
					//路劲底所有图片
					String[] list = f.list();
					String headimg ="";
					if(list!=null)
						headimg ="MoRenHead/"+list[0];
					user = new Users("", new Date(), "未录入" ,headimg,1,"",null);
					//保存soleCode
					user.setSoleCode(soleCode);
					//添加用户(游客)
					Serializable usersid = loginService.insertUsers(user);
					
					user.setId(Integer.parseInt(usersid.toString()));
					userinfo = new Userinfo();
					userinfo.setUsers(user);
					//融云注册
					userinfo.setChatToken("");
					//添加用户信息
					userinfoService.insertUserinfo(userinfo);
					Log4gUtil.Info("visitorLogin", userid+"", "添加用户为游客soleCode", soleCode, NF_callid, token);
				}else{
					/**
					 * 如soleCode存在
					 * 查询 用户信息
					 */
					//查询游客用户信息
					userinfo = userinfoService.selectUserinfo(user.getId());
					Log4gUtil.Info("visitorLogin", userid+"", "用户已为游客soleCode", soleCode, NF_callid, token);
				}
			}else{
				/**
				 * 二.如token存在,为账号用户,自动登录操作
				 * 
				 */
				userinfo.setAppOnline(1);//app账号上线
				newtoken = this.getToken(userinfo.getUsers().getPwd(),"");
				userinfo.setToken(newtoken);//更新token
				status = 1;//上线状态
				//缓存token
				user = userinfo.getUsers();//用户
				opApplic(user.getId()+"", newtoken);
				if(user.getNiuNum()==null||user.getNiuNum().equals("")){
					user.setNiuNum(getNiunum(user.getId()));
				}
				
				userinfoService.updateUserinfo(userinfo);
				Log4gUtil.Info("visitorLogin", userid+"", "自动登录操作", "成功", NF_callid, token);
			}
			
			
			Logins l = this.setLoginInfo(ip, user, mac, hotspotName, ver, deviceType, deviceVer, siteAreaid);
			loginService.insertLogins(l);
			
			//返回数据
			j.put("code", 1);
			j.put("status", status);//账号上线状态(1:上线 ; 0:未上线)
			j.put("token", newtoken);//新的token码
			j.put("userid", user.getId());
			j.put("headimg", IPUtil.getIp()+"/img/uersImg/headImg/"+user.getHeadImg());//头像地址
			j.put("sex", user.getSex());//性别(1:男,2女)
			j.put("selfdom",user.getSelfdom());//个性签名
			j.put("niuNum", user.getNiuNum());//牛号
			
			if(area!=null&&area.getLoginimgPic()!=null)//区域启动页图片
				j.put("areaimg", IPUtil.getIp()+"/img/loginImg/loginImg/"+area.getLoginimgPic());
			else
				j.put("areaimg", "");
			
			if(user.getPwd()!=null&&!user.getPwd().equals(""))//密码提示(1:有,0:无)
				j.put("pwd", 1);
			else
				j.put("pwd", 0);
			j.put("cloudUrl",  IPUtil.getYunfuwu());//云地址
			j.put("siteAreaid", siteAreaid);//所在区域（关口）
			j.put("chatToken",userinfo.getChatToken());//融云token码
			j.put("nickname", user.getNickname());//昵称
			j.put("isLogUploads", IPUtil.getIsLogUploads());//是否上传测试日志
			
			
		} catch (Exception e) {
			j.put("code", -1);
			j.put("msg", "服务器异常");
			e.printStackTrace();
		}
		out.print(j);
		Long endTime = new Date().getTime();
		Log4gUtil.Info("visitorLogin", userid+"", "输出自动登录时间", (startTime-endTime)+"-"+j.toString(), NF_callid, token);
		
	}
	/**
	 * 生成Token
	 * @param user 用户名(手机)
	 * @param pwd 密码
	 * @return token 
	 */
	
	private String getToken(String user ,String pwp){
		SimpleDateFormat  sdf = new SimpleDateFormat("yyyyMMddhhmmss");
		String token = Md5Util.getMd5(user+sdf.format(new Date())+RandomUtil.getRandom(4));
		return token;
	}
	/**
	 * 生成牛号
	 * @param userid
	 * @return
	 * @throws Exception
	 */
	private int getNiunum(int userid) throws Exception{
		int niu = 600054;
		return niu+userid;
	}
	
	/**
	 * 登陆信息
	 * @param ip
	 * @param users
	 * @param mac
	 * @param var
	 * @return
	 */
	private Logins  setLoginInfo(String ip,Users users,String mac,String hotspotName,
			String var,String deviceType,String devicever,int area ){
		Logins l =new Logins();
		
		if(deviceType==null){
			deviceType="";
		}
		l.setDeviceType(deviceType);
		if(devicever==null){
			devicever="";
		}
		l.setDeviceVer(devicever );
		if(hotspotName==null){
			hotspotName="";
		}
		l.setHotspotName(hotspotName);
		l.setAreaId(area);
		if(ip==null){
			ip="";
		}
		l.setDeviceIp(ip);
		if(mac==null){
			mac="";
		}
		l.setDeviceMac(mac);
		if(var==null){
			var="";
		}
		l.setVer(var);
		l.setLoginTime(new Date());
		l.setUsers(users);
		return l;
	}
	/**
	 * Appliction,token缓存
	 * @return
	 */
	private void opApplic(String key,Object str){
		ServletContext application =  ServletActionContext.getRequest().getSession().getServletContext();
		if(application.getAttribute(key)!=null){
			application.removeAttribute(key);
		}
		application.setAttribute(key, str);	
	}
	
	
	
	
	/*set和get*/
	public String getParams() {
		return params;
	}

	public void setParams(String params) {
		this.params = params;
	}
	public String getPwd() {
		return pwd;
	}
	

	public void setAccount(String account) {
		this.account = account;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}


	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getNickname() {
		return nickname;
	}

	public String getToken() {
		return token;
	}

	public String getAuthcode() {
		return authcode;
	}

	public LoginService getLoginService() {
		return loginService;
	}

	public AuthCodeService getAuthCodeService() {
		return authCodeService;
	}

	public BindingService getBindingService() {
		return bindingService;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public void setToken(String token) {
		this.token = token;
	}
	public void setAuthcode(String authcode) {
		this.authcode = authcode;
	}

	public void setMac(String mac) {
		this.mac = mac;
	}

	public void setAuthCodeService(AuthCodeService authCodeService) {
		this.authCodeService = authCodeService;
	}
	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

	public void setBindingService(BindingService bindingService) {
		this.bindingService = bindingService;
	}
	public void setVar(String ver) {
		this.ver = ver;
	}

	public void setId(int userid) {
		this.userid = userid;
	}

	public void setuserinfoService(UserinfoService userinfoService) {
		this.userinfoService = userinfoService;
	}


	

	public void setHotspotName(String hotspotName) {
		this.hotspotName = hotspotName;
	}


	public void setAreaService(AreaService areaService) {
		this.areaService = areaService;
	}

	public void setUseraccountService(UseraccountService useraccountService) {
		this.useraccountService = useraccountService;
	}

	public void setVer(String ver) {
		this.ver = ver;
	}

	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}

	public void setDeviceVer(String deviceVer) {
		this.deviceVer = deviceVer;
	}

	public void setUserinfoService(UserinfoService userinfoService) {
		this.userinfoService = userinfoService;
	}

	

	public void setSiteAreaid(int siteAreaid) {
		this.siteAreaid = siteAreaid;
	}
	public void setUserid(int userid) {
		this.userid = userid;
	}

	public void setSoleCode(String soleCode) {
		this.soleCode = soleCode;
	}

	public void setAccountType(int accountType) {
		this.accountType = accountType;
	}


	public void setAreaIpService(AreaIpService areaIpService) {
		this.areaIpService = areaIpService;
	}
	public void setDealService(DealService dealService) {
		this.dealService = dealService;
	}
	public void setNF_callid(String nF_callid) {
		NF_callid = nF_callid;
	}


	public void setTicketService(TicketService ticketService) {
		this.ticketService = ticketService;
	}


	public void setSex(int sex) {
		this.sex = sex;
	}


	public void setRecommend(String recommend) {
		this.recommend = recommend;
	}


	public void setRecommendService(RecommendService recommendService) {
		this.recommendService = recommendService;
	}


	public void setOpenId(String openId) {
		this.openId = openId;
	}

	
	
	
}
